//-----------------------------------------------------------------------
// <copyright file="SignInControlStyle.cs" company="Microsoft">
//     Copyright (c) Microsoft Corporation.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Microsoft.Live.Messenger.UI
{
    using System;
    using System.Diagnostics;
    using System.Text.RegularExpressions;

    /// <summary>
    /// Represents the <c>SignInControl</c> visual style.
    /// </summary>
    public sealed class SignInControlStyle
    {
        private readonly MessengerEntity entity;

        /// <summary>
        /// Initializes a new instance of the <see cref="SignInControlStyle"/> class.
        /// </summary>
        /// <remarks>
        /// The constructor is internal; this class should not be instantiated directly. Please see <see cref="SignInControl.Style"/>.
        /// </remarks>
        internal SignInControlStyle(object obj)
        {
            this.entity = new MessengerEntity(obj);
        }

        private string GetColor(string name)
        {
            return this.entity.GetProperty<string>(name);
        }

        private void SetColor(string name, string value)
        {
            Debug.Assert(!String.IsNullOrEmpty(name));

            if (String.IsNullOrEmpty(value))
            {
                throw ExceptionHelper.CreateArgumentNullException("value");
            }

            if (!Regex.IsMatch(value, "^#[0-9a-f]{6,6}$", RegexOptions.IgnoreCase))
            {
                throw ExceptionHelper.CreateArgumentOutOfRangeException("value");
            }

            this.entity.SetProperty<string>(name, value);
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s background color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string BackColor
        {
            get { return this.GetColor("BackColor"); }
            set { this.SetColor("BackColor", value); }
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s foreground color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string ForeColor
        {
            get { return this.GetColor("ForeColor"); }
            set { this.SetColor("ForeColor", value); }
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s border color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string BorderColor
        {
            get { return this.GetColor("BorderColor"); }
            set { this.SetColor("BorderColor", value); }
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s link color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string LinkColor
        {
            get { return this.GetColor("LinkColor"); }
            set { this.SetColor("LinkColor", value); }
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s button foreground color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string ButtonForeColor
        {
            get { return this.GetColor("ButtonForeColor"); }
            set { this.SetColor("ButtonForeColor", value); }
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s button background color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string ButtonBackColor
        {
            get { return this.GetColor("ButtonBackColor"); }
            set { this.SetColor("ButtonBackColor", value); }
        }

        /// <summary>
        /// Gets or sets the <c>SignInControl</c>'s button border color.
        /// </summary>
        /// <remarks>
        /// The color must be specified by using numbers to denote an RGB color value. An RGB color
        /// value must consist of a '#' immediately followed by a triad of two-digit hexadecimal
        /// numbers specifying the intensity of the corresponding color: (R)ed, (G)reen, and (B)lue.
        /// For example, the color value #FF0000 is rendered red because the red number is set to
        /// its highest value, FF (or 255, in decimal).
        /// </remarks>
        /// <exception cref="Exception"><c>value</c> is a null reference or empty.</exception>
        /// <exception cref="Exception"><c>value</c> is not a correctly formatted RGB color.</exception>
        public string ButtonBorderColor
        {
            get { return this.GetColor("ButtonBorderColor"); }
            set { this.SetColor("ButtonBorderColor", value); }
        }
    }
}